/**
 * Created by Administrator on 2016/8/30 0030.
 */
(function (){
    var app = angular.module('s9.service',[]);
    app.service('modelService', function ($http) {
        //this.add = function (name, phone, callback) {
        //    data.push(new Guest(name, phone));
        //    var isConnectSuccess = true; // 网络访问的成功与否
        //    if (isConnectSuccess) {
        //        callback({status: "success", message: '新增成功'})
        //    } else {
        //        callback({status: "failed", message: '新增失败'})
        //    }
        //};
        this.add=function(name, phone, callback){
            $http
                .get('http://192.168.26.72:8080/nl/add',{
                    params:{name:name,phone:phone}
                })
                .than(
                    function(res){
                       callback({status:res.data.state,message:res.data.message})
                    },
                    function(res){
                        callback({status:"faild",message:'错误'})
                    }

                )

            }
        this.del=function(guest,callback){
            $http
                .get('http://192.168.26.72:8080/nl/del',{
                    params:{name:guest.name,phone:guest.phone}
                })
                .than(
                    function(res){
                        callback({status:res.data.state,message:res.data.message})
                    },
                    function(res){
                        callback({status:"faild",message:'错误'})
                    }

                )
        }
        this.getList = function (state, callback) {
            $http
                .get('http://192.168.26.72:8080/nl/getList',{
                    params:{state:state}
                })
                .than(
                    function(res){
                        callback({status:res.data.state,message:res.data})
                    },
                    function(res){
                        callback({status:"faild",message:'错误'})
                    }

                )
        }
        this.setState = function (guest, state, callback) {
            $http
                .get('http://192.168.26.72:8080/nl/setState',{
                    params:{name:guest.name,phone:guest.phone,state:state}
                })
                .than(
                    function(res){
                        callback({status:res.data.state,message:res.data.message})
                    },
                    function(res){
                        callback({status:"faild",message:'错误'})
                    }

                )
        }

    })
})()